package com.fbs.job.core.model;

import java.io.Serializable;

public class ResultT<T> implements Serializable {
    private Integer code;
    private T data;
    private String msg;

    public static final int SUCCESS_CODE = 200;
    public static final int FAIL_CODE = 500;

    public ResultT() {
    }

    public ResultT(Integer code,String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResultT(T data) {
        this.code = SUCCESS_CODE;
        this.msg = "成功";
        this.data = data;
    }



    public static <T> ResultT<T> success() {
        ResultT resultReturn = new ResultT();
        resultReturn.code = SUCCESS_CODE;
        resultReturn.msg="执行成功!";
        return resultReturn;
    }

    public static <T> ResultT<T> success(T data) {
        ResultT resultReturn = new ResultT();
        resultReturn.code = SUCCESS_CODE;
        resultReturn.data = data;
        if (null!=data){
            resultReturn.msg = data.toString();
        }

        return resultReturn;
    }

    public static <T> ResultT<T> error(T data) {
        ResultT resultReturn = new ResultT();
        resultReturn.code = FAIL_CODE;
        resultReturn.data = data;
        resultReturn.msg = data.toString();
        return resultReturn;
    }








    public T getData() {
        return this.data;
    }

    public String getMessage() {
        return this.msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getCode() {
        return this.code;
    }
}
